using System.ComponentModel.DataAnnotations;

namespace JGSY.CMS.LowCode.Platform.Infrastructure.Configuration.Models;

/// <summary>
/// 扩展配置
/// </summary>
public class ExtensionConfiguration
{
    public bool EnableDatabaseExtensions { get; set; } = true;
    public bool AutoLoad { get; set; } = true;
    public string LogLevel { get; set; } = "info";
    public List<string> EnabledExtensions { get; set; } = new();
    public List<string> DisabledExtensions { get; set; } = new();
    public Dictionary<string, object> ExtensionSettings { get; set; } = new();
}

/// <summary>
/// MongoDB 配置
/// </summary>
public class MongoDbConfiguration
{
    [Required]
    public string Url { get; set; } = "mongodb://localhost:27017/cms";
    
    public string DatabaseName { get; set; } = "cms";
    public string Username { get; set; } = string.Empty;
    public string Password { get; set; } = string.Empty;
    public int MaxConnectionPoolSize { get; set; } = 100;
    public int MinConnectionPoolSize { get; set; } = 0;
    public int MaxConnectionIdleTime { get; set; } = 0;
    public int MaxConnectionLifeTime { get; set; } = 0;
    public int ConnectTimeout { get; set; } = 30000;
    public int SocketTimeout { get; set; } = 0;
    public bool UseSSL { get; set; } = false;
    
    public MongoDbOptionsConfiguration Options { get; set; } = new();
}

/// <summary>
/// MongoDB 选项配置
/// </summary>
public class MongoDbOptionsConfiguration
{
    public bool UseNewUrlParser { get; set; } = true;
    public bool UseUnifiedTopology { get; set; } = true;
    public int ServerSelectionTimeoutMS { get; set; } = 30000;
    public int HeartbeatFrequencyMS { get; set; } = 10000;
    public Dictionary<string, object> AdditionalOptions { get; set; } = new();
}

/// <summary>
/// ClickHouse 配置
/// </summary>
public class ClickHouseConfiguration
{
    [Required]
    public string Url { get; set; } = "http://localhost:8123";
    
    [Required]
    public string Database { get; set; } = "cms";
    
    public string Username { get; set; } = "default";
    public string Password { get; set; } = string.Empty;
    public int Timeout { get; set; } = 30;
    public bool Compress { get; set; } = true;
    public string CompressionMethod { get; set; } = "lz4";
    public int MaxConnections { get; set; } = 100;
    public int ConnectionTimeout { get; set; } = 10;
    public int CommandTimeout { get; set; } = 30;
    public bool UseHttps { get; set; } = false;
    public bool VerifySSL { get; set; } = true;
    
    /// <summary>
    /// 获取完整的连接字符串
    /// </summary>
    /// <returns>连接字符串</returns>
    public string GetConnectionString()
    {
        var connectionString = $"{Url}";
        
        if (!string.IsNullOrEmpty(Username) || !string.IsNullOrEmpty(Password))
        {
            var credentials = $"{Username}:{Password}";
            connectionString = connectionString.Replace("://", $"://{credentials}@");
        }
        
        return connectionString;
    }
}
